<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html body {  
            margin: 0;
            background-color: #000;
            padding: 0;
            overflow: hidden;
        }
    </style> 
</head>
<body>
    <canvas id="canvas"></canvas>
    <script>
        const canvas = document.getElementById('canvas')
        canvas.width = window.innerWidth 
        canvas.height = window.innerHeight 
        const ctx = canvas.getContext("2d")
        //字体大小
        const fontSize = 40  
        //列宽
        const columnWidth = fontSize
        //列数
        const columnNum = Math.floor(canvas.width / columnWidth)
        //每一列下一个文字是第几个
        const nextChar = new Array(columnNum).fill(0)
        //画一行文字
        function draw(){
             ctx.fillStyle = 'rgba(10,10,10,0.1)'
             ctx.fillRect(0,0,canvas.width, canvas.height)
            for(let i=0; i<nextChar.length; i++){
                //画一个字符
                ctx.fillStyle = 'green'
                ctx.font = `${fontSize}px`
                const char = getRandomChar()
                const x = i * columnWidth
                const y = (nextChar[i]+1) * fontSize  //canvas画文字,是以文字左下角为坐标起点
                ctx.fillText(char, x, y)
                if(y>canvas.height && Math.random()> 0.99){
                    nextChar[i] = 0 
                }else{ 
                    nextChar[i]++;
                }
            }
        }

        //随机字符串
        function getRandomChar(){
            let n = Math.random() * 10
            return Math.floor(n)
        }

        draw()
        setInterval(draw,30)
    </script>
</body>
</html>